package com.numbfish.ch81_ex01_testng_start;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
// import org.openqa.selenium.By;
// import org.openqa.selenium.WebDriver;
// import org.openqa.selenium.WebElement;
// import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

@SpringBootTest
@Slf4j

public class Ch81Ex01SeleniumStartTestApp {
    @Autowired
    private  ApplicationContext applicationContext;

    private WebDriver driver;

    @BeforeEach
    void setup() {
        this.driver = new HtmlUnitDriver();
    }

    @AfterEach
    void tearDown() {
        this.driver.quit();
    }

    @Test
    void test1(){
        driver.get("https://www.baidu.com/");
        WebElement element = driver.findElement(By.name("f"));
        System.out.println(element.getAttribute("name"));
        System.out.println(driver.getCurrentUrl());

    }

    @Test
    void test2(){

    }


    @Test
    void contextLoads() {
        log.info("applicationContext = {}",applicationContext);
    }
    @Test
    void beanCount(){
        // 用户未定义任何类时的bean个数为 springBoot2.7 : 139
        // 用户未定义任何类时的bean个数为 springBoot3   : 152
        log.info("applicationContext default bean count= {}",applicationContext.getBeanDefinitionNames().length);
    }


    void outputTheBeanFromContext(Class<?> clazz){
        // 用户未定义任何类时的bean个数为152
        log.info("applicationContext get a bean  {} === {}",clazz,applicationContext.getBean(clazz));
    }


}